<!--
        Copyright (c) 2023, LXMS (lxinet.cn).

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

     http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<template>
  <div class="searchBarBox">
    <a-form>
      <a-row :gutter="24">
        <a-col v-for="item in searchConfig" :key="item.key" v-bind="item.colProps||{span:5}">
          <a-form-item :label="item.title">
            <component :is="item.component"
                       v-model:value="formData[item.key]"
                       v-bind="item.props"
                       :placeholder="item.props && item.props.placeholder ? item.props.placeholder : '请输入' + item.title">

            </component>
          </a-form-item>
        </a-col>
        <a-button class="btn" type="primary" @click="handleSearch()" ghost>
          <template #icon>
            <SearchOutlined/>
          </template>
          查询
        </a-button>
        <a-button class="btn" @click="handleReset()">重置</a-button>
      </a-row>
    </a-form>
  </div>
</template>

<script>
import componentLibrary from "@components/componentLibrary";


export default {
  name: "lxSearchBar",
  props: {
    /**查询项配置**/
    searchConfig: {
      type: Array,
      default: () => [],
    },
    /**查询表单数据对象**/
    queryParams: {
      type: Object,
      default: () => ({}),
      required: true,
    },
    /**"更多查询"自定义点击事件**/
    onMoreClick: Function,
  },
  components: {
    ...componentLibrary,
  },
  data() {
    return {
      formData: {},

    }
  },
  methods: {
    handleSearch() {
      this.$emit('update:queryParams', this.formData);
      this.$nextTick(() => {
        this.$emit("onSearch")
      })
    },
    handleReset() {
      this.formData = {};
      this.$emit("onReset", this.formData);
      this.$nextTick(() => {
        this.handleSearch();
      })
    }
  },
  watch: {
    // queryParams(val){
    //   this.formData=val||{};
    // }
  },
}
</script>

<style lang="less" scoped>
.searchBarBox {
  position: relative;
  background: #FFFFFF;
  padding: 0px 20px 0px 20px;

  .ant-btn {
    margin-left: 15px;
  }

  .ant-form-item {
    margin-bottom: 10px !important;
  }
}
</style>